let app = getApp();
let util = app.globalData.util;
let wxApi = app.globalData.wxApi;
let Api = app.globalData.Api;
Page({
  data: {
    tabType: 1,
    saids: []
  },
  onLoad() {
    this.init();
  },
  init() {
    this.refreshSaids();
  },
  onStudentsSaid() {
    this.setData({
      tabType: 1
    })
  },
  onCooperation() {
  
    let url = 'https://ia.jydsapp.com/dfc/merchants.html';
    console.log( url );
    wxApi.navigateTo('../common/webview/webview', {
      src: url
    })
  },
  refreshSaids() {
    this.loadStudentsSaids( 1, saids => {
      this.setData({
        saids: saids
      })
    })
  },
  loadStudentsSaids(pageNo, callback) {
    let params = {
      pageNo: pageNo || 1
    }
    Api.studentsSaids( params, res => {
      let saids = this.saidsDateFormat( res.records );
      callback( saids );
    } )
  },
  saidsDateFormat( messages ) {
    let newMessages = [];
    for ( let i = 0, len = messages.length; i < len; i ++ ) {
      let message = messages[ i ];
      message.dateTime = util.dateFormat('yyyy.MM.dd mm:ss', message.createTime);
      newMessages.push( message );
    }
    return newMessages;
  },
  gotoMessageDetail( e ) {
    let link = e.currentTarget.dataset.link;
    wxApi.navigateTo('../common/webview/webview', {
      src: link
    })
  }
})